package authentication;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cht.sys.LDAP;

public class GetEmployeeNumberByName extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public GetEmployeeNumberByName() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding( "UTF-8" );
		response.setCharacterEncoding( "UTF-8" );
		response.setContentType("application/text");
		final String name = request.getParameter("val");
		final String SPLIT = request.getParameter("split");
		final ArrayList arr = LDAP.getEmployeeNumberByName(name);
		String res = "";
		
		for(int i=0; i<arr.size();i++) {
			res += ((String)arr.get(i)).trim()+SPLIT;
		}
		 
		if ( !"".equalsIgnoreCase(res) ) {
			res = res.substring(0, (res.length()- SPLIT.length()) );
		} else {
			res = "";
		}
		
		response.getWriter().write( res );
	}

}
